package com.baaio.swing;

import java.io.File;
import java.io.FileInputStream;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;


public class I18N
{
	private String getValueHandle(String str) throws Exception
	{
		
		FileInputStream is;
		ResourceBundle bundle = null;
		try
		{
			is = new FileInputStream(new File("src/Baaio.properties"));
			Properties pp = new Properties();
			pp.load(is);
			String locale = pp.getProperty("language");
			Locale[] locale2 = Locale.getAvailableLocales();
			String language = "";
			String k = locale.toUpperCase();
			for(Locale l : locale2)
			{
				if(k.equals(l.getCountry()))
				{
					language = l.getLanguage();
					break;
				}
			}
			Locale locale3 = new Locale(language,k);
			bundle = ResourceBundle.getBundle("baaio",locale3);
			
		}
		catch (Exception e)
		{
			bundle = ResourceBundle.getBundle("baaio", Locale.getDefault());
		}
		
		return bundle.getString(str);
	}
	
	public String getValue(String str)
	{
		try
		{
			str = getValueHandle(str);
		}
		catch (Exception e)
		{
			return str;
		}
		return str;
	}
	
	public static void main(String[] args)
	{

		System.out.println(new I18N().getValue("okButton"));
	}


}
